<%@page import="rjeutsky.models.Publication"%>
<%@page import="rjeutsky.ControllerWrapper"%>
<%@page import="rjeutsky.models.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Редактировать Издание</title>
</head>
<%
	if (session.getAttribute("currentUser") == null) {
		response.sendRedirect("Login.jsp");
	}

	boolean isAdmin = rjeutsky.ControllerWrapper
			.getApplicationController().checkIsAdmin(
					(User) session.getAttribute("currentUser"));
	if (!isAdmin) {
		response.sendError(403);
	}

	try {
		Long id = Long.parseLong(request.getParameter("id"));
		Publication selectedPublication = ControllerWrapper
				.getApplicationController().getPublication(id);
		if (selectedPublication == null) {
			response.sendError(404);
		} else {
			pageContext.setAttribute("publication", selectedPublication);
		}
	} catch (NumberFormatException ex) {
		response.sendError(404);
	}
%>

<body>
	<table>
		<tr>
			<td><jsp:include page="Menu.jsp" /></td>
			<td>
			<span>Редактировать Издание</span><span class="validationError">${param.validationError}</span>
			<form action="${pageContext.request.contextPath}/EditPublication" method="post" >
			<input type="hidden" name="id" value="${publication.id}" />
			<fieldset><label>Название</label><input type="text" name="name" value="${publication.name }" /></fieldset>
			<fieldset><label>Цена</label><input type="text" name="price" value="${publication.price}" /></fieldset>
			<input type="submit" name="submit" value="Сохранить" /> 
			</form>
			<td>
		</tr>
	</table>
</body>
</html>